/*
* @Author: Marte
* @Date:   2018-10-31 20:59:18
* @Last Modified by:   Marte
* @Last Modified time: 2018-11-01 10:01:32
*/
const TypeDao = require("../dao/type/type_dao.js")

const TypeService={
	add(req,res,next){
		const {department,profession,describe}=req.body;
		console.log(req.body);
		TypeDao.save({department,profession,describe})
										.then((data)=>{
											res.json({
												res_code:1,
												res_error:"",
												res_body:{
													status:1,
													data:data
												}
											});
										})
							.catch((err) => {
								res.json({
									res_code: 0,
									res_error: err,
									res_body: {}
								})
							});
	},
	findByPage(req, res, next) {

		const {page} = req.query;
		console.log({page});
		TypeDao.findByPage(page)
							.then((data) => {
								res.json({
									res_code: 1,
									res_error: "",
									res_body: {
										status: 1,
										list: data
									}
								});
							})
							.catch((err) => {
								res.json({
									res_code: 0,
									res_error: err,
									res_body: {}
								});
							});
	},
	removeByPro(req,res,next){
		const {profession} = req.query;
		console.log({profession});
		TypeDao.removeByPro({profession})
							.then((data)=>{
								res.json({
									res_code: 1,
									res_error: "",
									res_body: {
										status: 1,
									}
								});								
								
							})
							.catch((err)=>{
								res.json({
									res_code: 0,
									res_error: err,
									res_body: {}
								});								
							});
		
	},
	update(req,res,next){
		const {department} = req.body;
		
		const {profession,describe} = req.body;
		
		console.log({department});
		console.log({profession,describe});
		TypeDao.update({department},{profession,describe})
							.then((data)=>{
								res.json({
									res_code: 1,
									res_error: "",
									res_body: {
										status: 1,
										data:data
									}
								});								
								
							})
							.catch((err)=>{
								res.json({
									res_code: 0,
									res_error: err,
									res_body: {}
								});								
							});
		
	}		
};
module.exports = TypeService;
